package org.thss.petri.gef.editparts;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.thss.petri.gef.editparts.policies.TokenComponentEditPolicy;
import org.thss.petri.model.NodeConstraint;
import org.thss.petri.model.Place;
import org.thss.petri.model.Token;


public class TokenEditPart extends AbstractGraphicalEditPart implements Adapter {
	public static int TOKEN_WIDTH = 10;
	public static int TOKEN_HEIGHT = 10;
	
	private Token model;

	public TokenEditPart(Token model) {
		this.model = model;
		setModel(model);
	}

	@Override
	protected IFigure createFigure() {
		Ellipse shape = new Ellipse();
		shape.setBackgroundColor(ColorConstants.black);
		shape.setSize(TOKEN_WIDTH, TOKEN_HEIGHT);
		return shape;
	}

	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new TokenComponentEditPolicy());
	}

	@Override
	protected void refreshVisuals() {
	}

	@Override
	public void notifyChanged(Notification notification) {
		refreshVisuals();
	}
	
	@Override
	public void activate() {
		if (isActive()) {
			return;
		}
		super.activate();
		((Notifier) getModel()).eAdapters().add(this);
	}
	
	@Override
	public void deactivate() {
		if (!isActive()) {
			return;
		}
		super.deactivate();
		((Notifier) getModel()).eAdapters().remove(this);
	}

	@Override
	public Notifier getTarget() {
		return model;
	}

	@Override
	public void setTarget(Notifier newTarget) {
		model = (Token) newTarget;
		setModel(model);
	}

	@Override
	public boolean isAdapterForType(Object type) {
		return type.equals(Token.class);
	}

}
